package com.gz.servlet.servletcontext;

import javax.servlet.ServletContext;

public class WebUtils {
    public static Integer visitcount(ServletContext servletContext){
        //1.从servletContext获取属性visit_count 属性 (相当于记录的Map的k-v数)
        Object visit_count = servletContext.getAttribute("visit_count");
        if(visit_count == null) {
            //说明是第一次访问
            servletContext.setAttribute("visit_count", 1);
            visit_count=1;//一定要写，否则return返回的还是null
        }else{
            int i = Integer.parseInt(visit_count.toString());
            //访问一次就+1
            i++;
            servletContext.setAttribute("visit_count", i);
        }
        return  Integer.parseInt(visit_count.toString());
    }
}
